package com.ba360.struts.form;

import com.ba360.portal.database.dbo.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class ResponseForm extends ActionForm
{
  private String respEmail;
  private String respMessage;
  private String adId;
  private String adTitle;

  public void setAdId(String adId)
  {
    this.adId = adId;
  }

  public String getAdId() {
    return this.adId; }

  public void setAdTitle(String adTitle) {
    this.adTitle = adTitle;
  }

  public String getAdTitle() {
    return this.adTitle;
  }

  public void setRespEmail(String respEmail) {
    this.respEmail = respEmail;
  }

  public String getRespEmail() {
    return this.respEmail;
  }

  public void setRespMessage(String respMessage)
  {
    this.respMessage = respMessage;
  }

  public String getRespMessage() {
    return this.respMessage;
  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
  {
    ActionErrors ae = new ActionErrors();
    if (request.getParameter("action") != null) {
      if ((this.respEmail == null) || (this.respEmail.equals(""))) {
        ae.add("Email Address", new ActionError("error.email.value"));
      }

      if ((this.respEmail.indexOf("@") == -1) || (this.respEmail.indexOf(".") == -1) || 
        (this.respEmail.length() < 8))
        ae.add("Email", new ActionError("error.invalidemail.value"));
      if ((this.respMessage == null) || (this.respMessage.equals("")))
        ae.add("Response Message", 
          new ActionError("error.respmessage.value"));

    }

    User user = (User)request.getSession().getAttribute("USER");
    if (user != null)
    {
      this.respEmail = user.getEmail();
    }
    return ae;
  }

  public void reset(ActionMapping mapping, HttpServletRequest request)
  {
  }
}